﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Pavilion
{
    public class GameData
    {
        public IGameDataInfo DataInfo { get; set; }
        public Dictionary<string, object> PropertyDictionary { get { return (propertyDictionary == null) ? propertyDictionary = new Dictionary<string, object>() : propertyDictionary; } }

        private Dictionary<string, object> propertyDictionary;

        public GameData(IGameDataInfo dataInfo)
        {
            this.DataInfo = dataInfo;
        }

        public void AddData(string propertyName, string propertyValue)
        {
            PropertyDictionary.Add(propertyName, DataInfo.ObtainPropertyInfo(propertyName).ConvertData(propertyValue));
        }

        public void AddData(string propertyName, object propertyValue)
        {
            PropertyDictionary.Add(propertyName, propertyValue);
        }
    }

    public interface IGameDataInfo
    {
        string ToolName { get; }
        IEnumerable<string> CompletePropertyList { get; }

        GamePropertyInfo ObtainPropertyInfo(string propertyName);
    }

    public struct GamePropertyInfo
    {
        public object DefaultValue { get { return defaultValue; } }

        private object defaultValue;
        private Func<string, object> converter;

        public GamePropertyInfo(Func<string, object> converter, object defaultValue)
        {
            this.converter = converter;
            this.defaultValue = defaultValue;
        }

        public object ConvertData(string propertyValue)
        {
            return converter.Invoke(propertyValue);
        }
    }
}
